Completed
Push — master ( f32ba6...d43b85 )
by Yannick
30:30
created

map.common.js ➔ clickAPRS   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 1
1
function getCookie(cname) {
2
    var name = cname + "=";
3
    var ca = document.cookie.split(';');
4
    for(var i=0; i<ca.length; i++) {
5
	var c = ca[i];
6
	while (c.charAt(0)==' ') c = c.substring(1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7
	if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8
    }
9
    return "";
10
}
11
12
function delCookie(cname) {
13
    document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
14
}
15
16
function createCookie(name, value, days) {
17
    var date, expires;
18
    if (days) {
19
	date = new Date();
20
	date.setTime(date.getTime()+(days*24*60*60*1000));
21
	expires = "; expires="+date.toGMTString();
22
    } else {
23
	expires = "";
24
    }
25
    document.cookie = name+"="+value+expires+"; path=/";
26
}
27
28
function mapType(selectObj) {
29
    var idx = selectObj.selectedIndex;
30
    var atype = selectObj.options[idx].value;
31
    var type = atype.split('-');
32
    if (type[0] == 'Mapbox') {
33
	createCookie('MapType',type[0],9999);
34
	createCookie('MapTypeId',type[1],9999);
35
	if (getCookie('Map2D3DSync')) {
36
	    createCookie('MapType3D',type[0],9999);
37
	    createCookie('MapType3DId',type[1],9999);
38
	}
39
    } else {
40
	createCookie('MapType',atype,9999);
41
	if (getCookie('Map2D3DSync')) {
42
	    createCookie('MapType3D',atype,9999);
43
	}
44
    }
45
    window.location.reload();
46
}
47
function mapType3D(selectObj) {
48
    var idx = selectObj.selectedIndex;
49
    var atype = selectObj.options[idx].value;
50
    var type = atype.split('-');
51
    if (type[0] == 'Mapbox') {
52
	createCookie('MapType3D',type[0],9999);
53
	createCookie('MapType3DId',type[1],9999);
54
	if (getCookie('Map2D3DSync')) {
55
	    createCookie('MapType',type[0],9999);
56
	    createCookie('MapTypeId',type[1],9999);
57
	}
58
    } else {
59
	createCookie('MapType3D',atype,9999);
60
	if (getCookie('Map2D3DSync')) {
61
	    createCookie('MapType',atype,9999);
62
	}
63
    }
64
    window.location.reload();
65
}
66
function clickSyncMap2D3D(cb) {
67
    createCookie('Map2D3DSync',cb.checked,9999);
68
    if (cb.checked) {
69
	createCookie('MapType3D',getCookie('MapType'),9999);
70
	createCookie('MapType3DId',getCookie('MapTypeId'),9999);
71
    }
72
}
73
74
function terrainType(selectObj) {
75
    var idx = selectObj.selectedIndex;
76
    var atype = selectObj.options[idx].value;
77
    var type = atype.split('-');
78
    document.cookie =  'MapTerrain='+type+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
79
    createCookie('MapTerrain',type,9999);
80
    if (type == 'stk') {
81
	stkterrain();
82
    } else if (type == 'articdem') {
83
	articterrain();
84
    } else if (type == 'ellipsoid') {
85
	ellipsoidterrain();
86
    } else if (type == 'vrterrain') {
87
	vrtheworldterrain();
88
    }
89
    //window.location.reload();
90
}
91
92
function sattypes(selectObj) {
93
    var sattypes = [], sattype;
94
    for (var i=0, len=selectObj.options.length; i< len;i++) {
95
	sattype = selectObj.options[i];
96
	if (sattype.selected) {
97
	    sattypes.push(sattype.value);
98
	}
99
    }
100
    createCookie('sattypes',sattypes.join(),2);
101
    updateSat();
102
}
103
function airlines(selectObj) {
104
    var airs = [], air;
105
    for (var i=0, len=selectObj.options.length; i< len;i++) {
106
	air = selectObj.options[i];
107
	if (air.selected) {
108
	    airs.push(air.value);
109
	}
110
    }
111
    createCookie('filter_Airlines',airs.join(),2);
112
}
113
function airlinestype(selectObj) {
114
    var idx = selectObj.selectedIndex;
115
    var airtype = selectObj.options[idx].value;
116
    createCookie('filter_airlinestype',airtype,2);
117
}
118
function racefilter(selectObj) {
119
    var idx = selectObj.selectedIndex;
120
    var race = selectObj.options[idx].value;
121
    createCookie('filter_race',race,2);
122
}
123
function alliance(selectObj) {
124
    var idx = selectObj.selectedIndex;
125
    var alliance = selectObj.options[idx].value;
126
    createCookie('filter_alliance',alliance,2);
127
}
128
function identfilter() {
129
    var ident = $("#identfilter").value;
130
    createCookie('filter_ident',ident,2);
131
}
132
function mmsifilter() {
133
    var ident = $("#mmsifilter").value;
134
    createCookie('filter_mmsi',ident,2);
135
}
136
function removefilters() {
137
    // Get an array of all cookie names (the regex matches what we don't want)
138
    var cookieNames = document.cookie.split(/=[^;]*(?:;\s*|$)/);
139
    // Remove any that match the pattern
140
    for (var i = 0; i < cookieNames.length; i++) {
141
	if (/^filter_/.test(cookieNames[i])) {
142
	    delCookie(cookieNames[i]);
143
	}
144
    }
145
    window.location.reload();
146
}
147
function sources(selectObj) {
148
    var sources = [], source;
149
    for (var i=0, len=selectObj.options.length; i< len;i++) {
150
	source = selectObj.options[i];
151
	if (source.selected) {
152
	    sources.push(source.value);
153
	}
154
    }
155
    createCookie('filter_Sources',sources.join(),2);
156
}
157
158
159
function show2D() {
160
    createCookie('MapFormat','2d',10);
161
    if (document.getElementById("pointtype").className == 'tracker') {
162
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
163
    } else if (document.getElementById("pointtype").className == 'marine') {
164
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
165
    } else {
166
	createCookie('MapTrack',document.getElementById("pointident").className,1);
167
    }
168
    window.location.reload();
169
}
170
function show3D() {
171
    createCookie('MapFormat','3d',10);
172
    if (document.getElementById("pointtype").className == 'tracker') {
173
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
174
    } else if (document.getElementById("pointtype").className == 'marine') {
175
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
176
    } else {
177
	createCookie('MapTrack',document.getElementById("pointident").className,1);
178
    }
179
    window.location.reload();
180
}
181
function clickPolar(cb) {
182
    createCookie('polar',cb.checked,9999);
183
    window.location.reload();
184
}
185
function clickDisplayAirports(cb) {
186
    createCookie('displayairports',cb.checked,9999);
187
    window.location.reload();
188
}
189
function clickDisplayISS(cb) {
190
    createCookie('displayiss',cb.checked,9999);
191
    updateSat();
192
}
193
function clickDisplayMinimap(cb) {
194
    createCookie('displayminimap',cb.checked,9999);
195
    window.location.reload();
196
}
197
function clickShadows(cb) {
198
    createCookie('map3dnoshadows',cb.checked,9999);
199
    window.location.reload();
200
}
201
function clickSingleModel(cb) {
202
    createCookie('singlemodel',cb.checked,9999);
203
}
204
function clickUpdateRealtime(cb) {
205
    createCookie('updaterealtime',cb.checked,9999);
206
}
207
function clickVATSIM(cb) {
208
    createCookie('filter_ShowVATSIM',cb.checked,2);
209
}
210
function clickIVAO(cb) {
211
     createCookie('filter_ShowIVAO',cb.checked,2);
212
}
213
function clickphpVMS(cb) {
214
    createCookie('filter_ShowVMS',cb.checked,2);
215
}
216
function clickSBS1(cb) {
217
    createCookie('filter_ShowSBS1',cb.checked,2);
218
}
219
function clickAPRS(cb) {
220
    createCookie('filter_ShowAPRS',cb.checked,2);
221
}
222
function clickDisplayGroundStation(cb) {
223
    createCookie('show_GroundStation',cb.checked,2);
224
    window.location.reload();
225
}
226
function clickDisplayWeatherStation(cb) {
227
    createCookie('show_WeatherStation',cb.checked,2);
228
    window.location.reload();
229
}
230
function clickDisplayWeather(cb) {
231
    createCookie('show_Weather',cb.checked,2);
232
//    window.location.reload();
233
}
234
function clickDisplayLightning(cb) {
235
    createCookie('show_Lightning',cb.checked,2);
236
    window.location.reload();
237
}
238
function clickDisplayFires(cb) {
239
    createCookie('show_Fires',cb.checked,2);
240
    window.location.reload();
241
}
242
function clickDisplay2DBuildings(cb) {
243
    createCookie('Map2DBuildings',cb.checked,2);
244
    window.location.reload();
245
}
246
function unitdistance(selectObj) {
247
    var idx = selectObj.selectedIndex;
248
    var unit = selectObj.options[idx].value;
249
    createCookie('unitdistance',unit,9999);
250
}
251
function unitspeed(selectObj) {
252
    var idx = selectObj.selectedIndex;
253
    var unit = selectObj.options[idx].value;
254
    createCookie('unitspeed',unit,9999);
255
}
256
function unitaltitude(selectObj) {
257
    var idx = selectObj.selectedIndex;
258
    var unit = selectObj.options[idx].value;
259
    createCookie('unitaltitude',unit,9999);
260
}
261
function addarchive(begindate,enddate) {
262
    console.log('Add archive');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
263
    createCookie('archive',true,2);
264
    createCookie('archive_begin',begindate,2);
265
    createCookie('archive_end',enddate,2);
266
    createCookie('archive_speed',document.getElementById("archivespeed").value,2);
267
    window.location.reload();
268
}
269
function noarchive() {
270
    console.log('Exit archive!');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
271
    delCookie('archive');
272
    delCookie('archive_begin');
273
    delCookie('archive_end');
274
    delCookie('archive_speed');
275
    window.location.reload();
276
}
277
function msgbox(text,buttontext) {
278
	buttontext = buttontext || "OK";
279
	$("<div>" + text + "</div>").dialog({
280
	    dialogClass: "no-close",
281
	    buttons: [{
282
		text: buttontext,
283
		click: function() {
284
		    $( this ).dialog( "close" );
285
		    $(this).remove();
286
		}
287
	    }]
288
	});
289
}
290
function generateRandomPoint (latitude,longitude,height,diff,radius) {
291
292
	//console.log('height: '+height+' - diff: '+diff);
293
	radius = Math.random()*radius;
294
	latitude = latitude*(Math.PI/180.0);
295
	longitude = longitude*(Math.PI/180.0);
296
	
297
	const sinLat = 	Math.sin(latitude)
298
	const cosLat = 	Math.cos(latitude)
299
300
	/* go fixed distance in random direction*/
301
	const bearing = Math.random() * Math.PI*2
302
	const theta = radius/6371000
303
	const sinBearing = Math.sin(bearing)
304
	const cosBearing = Math.cos(bearing)
305
	const sinTheta = Math.sin(theta)
306
	const cosTheta = Math.cos(theta)
307
    
308
	latitude = Math.asin(sinLat*cosTheta+cosLat*sinTheta*cosBearing);
309
	longitude = longitude + Math.atan2( sinBearing*sinTheta*cosLat, cosTheta-sinLat*Math.sin(latitude ));
310
	/* normalize -PI -> +PI radians */
311
	longitude = ((longitude+(Math.PI*3))%(Math.PI*2))-Math.PI
312
	var h = height+(Math.random()*diff)
313
	//console.log('h: '+h);
314
	return {
315
	    latitude: latitude/(Math.PI/180.0),
316
	    longitude: longitude/(Math.PI/180.0),
317
	    height: h
318
	};
319
}
320
function getColor(colorStart,colorEnd,colorCount,step) {
321
	var alpha = (1.0/colorCount)*step;
322
	return {
323
	    r: colorStart[0]*alpha+(1-alpha)*colorEnd[0],
324
	    v: colorStart[1]*alpha+(1-alpha)*colorEnd[1],
325
	    b: colorStart[2]*alpha+(1-alpha)*colorEnd[2]
326
	};
327
}